package com.fpj.sat.vehicle_administrator.view;

import java.awt.Component;
import java.awt.Font;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

import com.fpj.sat.vehicle_administrator.action.LoginAction;
import com.fpj.sat.vehicle_administrator.util.JTextFieldLimit;
import com.fpj.sat.vehicle_administrator.util.Util;

public class LoginPanel extends JPanel{

	private static final long serialVersionUID = 362889171272845230L;
	private PrincipalFrame principal;
	private JLabel lblTitulo;
	private JLabel lblUsuario;
	private JLabel lblPassword;
	private JTextField txtUsuario;
	private JPasswordField txtPassword;
	private JButton btnIngresar;
	
	public LoginPanel(PrincipalFrame principal) {
		this.principal = principal;
		inicializaPanel();
		inicializaComponentes();
	}

	private void inicializaPanel() {
		setLayout(null);
		setBounds(0, 0, principal.getWidth(), principal.getHeight());
	}

	private void inicializaComponentes() {
		lblTitulo = new JLabel("LOGIN");
		lblTitulo.setFont(new Font(lblTitulo.getFont().getFontName(), Font.BOLD, 16));
		lblTitulo.setBounds(Util.getPorcentaje(getWidth(), 0.5) - 20, 10, 200, 25);
		
		lblUsuario = new JLabel("Usuario: ");
		lblUsuario.setBounds(
				Util.getPorcentaje(principal.getWidth(), 0.5) - 80, 
				Util.getPorcentaje(principal.getHeight(), 0.5) - 40, 70, 20);
		
		lblPassword = new JLabel("Password: ");
		lblPassword.setBounds(
				Util.getPorcentaje(principal.getWidth(), 0.5) - 80, 
				Util.getPorcentaje(principal.getHeight(), 0.5) - 15, 70, 20);
		
		txtUsuario = new JTextField();
		txtUsuario.setDocument(new JTextFieldLimit(10));
		txtUsuario.setBounds(
				Util.getPorcentaje(principal.getWidth(), 0.5) - 10, 
				Util.getPorcentaje(principal.getHeight(), 0.5) - 40, 90, 25);
		
		txtPassword = new JPasswordField();
		txtPassword.setDocument(new JTextFieldLimit(20));
		txtPassword.setBounds(
				Util.getPorcentaje(principal.getWidth(), 0.5) - 10, 
				Util.getPorcentaje(principal.getHeight(), 0.5) - 15, 90, 25);
		
		btnIngresar = new JButton("Ingresar");
		btnIngresar.setBounds(
				Util.getPorcentaje(principal.getWidth(), 0.5) - 50, 
				Util.getPorcentaje(principal.getHeight(), 0.5) + 20, 100, 25);
		btnIngresar.addActionListener(new LoginAction(this, principal));
		
		agregarComponentes(lblTitulo, lblUsuario, lblPassword, txtUsuario, txtPassword, btnIngresar);
	}
	
	private void agregarComponentes(Component...componentes){
		for(Component component: componentes){
			add(component);
		}
		
	}

	public JTextField getTxtUsuario() {
		return txtUsuario;
	}

	public void setTxtUsuario(JTextField txtUsuario) {
		this.txtUsuario = txtUsuario;
	}

	public JPasswordField getTxtPassword() {
		return txtPassword;
	}

	public void setTxtPassword(JPasswordField txtPassword) {
		this.txtPassword = txtPassword;
	}
	
	


}
